package com.fan.util;
import com.fan.game.Explode;

import java.util.ArrayList;
import java.util.List;

public class ExplodePool {


    public static final int DEFAULT_POOL_SIZE = 20;
    public static final int POOL_MAX_SIZE = 10;

    //用于保存所有爆炸效果的容器
    private static List<Explode> pool = new ArrayList<>();

    static {
        for (int i = 0; i < DEFAULT_POOL_SIZE; i++) {
            pool.add(new Explode());
        }
    }


    //从池塘获取一个爆炸对象
    public static Explode get(){
        Explode explode = null;
        //池塘被掏空
        if(pool.size() == 0){
            explode =new Explode();
        }
        //还有对象
        else{
            explode = pool.remove(0);
        }
        return explode;
    }


    public static void theReturn(Explode explode ){

        if(pool.size() == POOL_MAX_SIZE){
            return;
        }
        pool.add(explode);
    }
}
